<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */
 

class tbdata_queue_propgets{

    function run(&$cursor_id,$params){
          //每次最多处理1个子分类
        $model = app::get('tbdata')->model('cats');
		$sync = kernel::single('tbdata_sync');
        $db = kernel::database();
		$filter = $params['filter'];
		$cid = $filter['cid'];
		$rows = $model->getList('*',array('cid'=>$cid),0,1);
		if($rows[0]['is_parent']=='true'){
			$leaf_cid = $this->get_one_leaf($cid,$params['queue_time']);
		}else{
			$leaf_cid = $rows[0]['cid'];
		}
		$sync->get_props($leaf_cid);
		$model->update(array('props_download_time'=>time()),array('cid'=>$leaf_cid));
		if($this->get_one_leaf($cid,$params['queue_time'])){
			return 1;
		}else{
			$model->update(array('props_download_time'=>time()),array('cid'=>$cid));
			return 0;
		}

    }
	function get_one_leaf($cid,$queue_time){
        $model = app::get('tbdata')->model('cats');
		$rows = $model->getList('*',array('parent_cid'=>$cid,'props_download_time|sthan'=>$queue_time),0,-1);
		
		foreach($rows as $row){
			if($row['is_parent']=='true'){
				return $this->get_one_leaf($cid,$queue_time);
			}else{
				$return = $row['cid'];
				return $return;
			}
		}
	}
}
